import { getToken } from 'initHandler.js'

const md5 = require('./md5.js');
//当前月份
export const formatDateMonth = date => {

  const month = date.getMonth() + 1
  return month
}
//当月
export const formatDate = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1 //8
  const day = date.getDate()
  return [year, month, day].map(formatNumber).join('-');
}

//向前两个月
export const formatDateMothTwo = date => {
  const year = date.getFullYear()
  const month = date.getMonth()  //7
  return [year, month - 1, 15].map(formatNumber).join('-');
}

export const getTime = (year, month) => {
  return [year, month, 15].map(formatNumber).join('-');
}
export const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


export function getSignatur(data) {
  var reg = /^[\u4E00-\u9FA5]+$/;
  var sign = '';
  var str = '';

  const signKeys = Object.keys(data).filter((key) => data[key] !== null && data[key] !== undefined);
  signKeys.forEach((key, index) => {
    if (index < signKeys.length) {
      if ((escape(data[key]).indexOf("%u") < 0)) {
        str += key + '=' + data[key] + "&";
      }
    }
  })
  sign = "!@#$%^&*" + str + '*&^%$#@'
  sign = md5.hexMD5(sign);
  return 1;
}

